package com.hikvision.open.app.utils

import android.content.pm.PackageManager
import java.util.concurrent.ConcurrentHashMap

/**
 * 权限请求结果处理类
 */
class PermissionResultHandler {
    companion object {
        private val callbacks = ConcurrentHashMap<Int, ((IntArray) -> Unit)?>()

        /**
         * 添加权限请求回调
         */
        fun addCallback(requestCode: Int, callback: (IntArray) -> Unit) {
            callbacks[requestCode] = callback
        }

        /**
         * 处理权限请求结果
         */
        fun handlePermissionsResult(requestCode: Int, grantResults: IntArray): Boolean {
            val callback = callbacks[requestCode]
            callback?.invoke(grantResults)
            callbacks.remove(requestCode)
            return callback != null
        }
    }
}